(function(window){
    window.frameAnimation = {
        anims:(function(){
            return function(obj,frames,eachtime,times, callback){
                var runing = false;
                var handler = null;         //obj,frames,eachtime,times定时器
                var step = 0;       //当前帧
                var time = 0;       //当前第几轮
                var steps = frames.length;          //帧数
                var speed = eachtime*1000/steps;      //间隔时间
                function _play(){
                    if(step >=steps){
                            step = 0;
                            time++;
                    }
                    if(0 == times || time <times){
                        //obj.attr("src",frames[step]);
                        obj.css({
                        	"background": "url("+share[step]+") no-repeat"
                        });
                        step++;
                    }else{
                        control.stop();
                        callback && callback();
                    }
                }
                
                var control = {
                    start:function(){
                        if(!runing){
                            runing = true;
                            step = time = 0;
                            handler = setInterval(_play, speed);
                        }
                        return this;
                    },
                    stop:function(restart){
                        if(runing){
                            runing = false;
                            if(handler){
                                clearInterval(handler);
                                handler = null;
                            }
                            if(restart){
                                //obj.attr('src',frames[0]);
                                obj.css({
		                        	"background": "url("+share[0]+") no-repeat"
		                        });
                                step = 0;
                                time = 0;
                            }
                        }
                    }
                    ,dispose:function(){
                        this.stop();
                    }
                };
                return control;
            }
        })()
    }
})(window);